'''
Created on Oct 12, 2012

@author: peng
'''
import time
from time import mktime
from datetime import datetime


def str_to_time(time_str):
    t = time.strptime(time_str, "%Y-%m-%d")
    try:
        return int(mktime(t))
    except AttributeError:
        return None


def unix_time(value=None):
    if not value:
        value = datetime.utcnow()
    try:
        return int(mktime(value.timetuple()))
    except AttributeError:
        return None


t = str_to_time("2012-10-10")
print t

s = (t / (3600 * 24)) * 3600 * 24

print s
print datetime.fromtimestamp(s)
